package com.xcity.game.combat.skill.impl;

import java.util.List;

import com.xcity.game.combat.Action;
import com.xcity.game.combat.Round;
import com.xcity.game.combat.attr.CombatAttributeType;
import com.xcity.game.combat.buff.CombatBuff;
import com.xcity.game.combat.skill.CombatSkill;
import com.xcity.game.combat.unit.CombatUnit;
import com.xcity.game.skill.Skill;

/**
 * 天生我才<br/>
 * 为所有员工加油打气，提升相当于玩家智力*{0=1.125#0}的防御力，持续{1=2#0}回合
 * @author yang.li
 *
 */
public class COMBAT_SKILL_100004 extends CombatSkill {

	public COMBAT_SKILL_100004(Skill skill) {
		super(skill);
	}

	@Override
	public void calcDamage(Action action) {
		List<CombatUnit> units = action.unit.getTeam().all();
		for (int i = 0; i < units.size(); i++) {
			CombatUnit unit = units.get(i);
			if (!unit.isDied()) {
				// +defense
				action.addBuff(new BUFF(skill, unit, action.unit));
			}
		}
	}
	
	static class BUFF extends CombatBuff {
		int oldDefense;
		public BUFF(Skill skill, CombatUnit owner, CombatUnit releaser) {
			super(skill.getTemplate().getCombatBuff(), owner, (int) skill.getParameter(1));
			active = true;
			int defense = (int) owner.getDefense();
			oldDefense = defense;
//			defense += releaser.getINT() * template.getInitVal(0);
			defense += 1;
			owner.setAttributeValue(CombatAttributeType.DEFENSE, defense);
		}
		@Override
		public void roundEnd(Round round) {
			super.roundEnd(round);
			if (state == STATE_REMOVED) {
				owner.setAttributeValue(CombatAttributeType.DEFENSE, oldDefense);
			}
		}
	}

}
